<%@page import="com.shsh.safemanage.util.Util"%>
<%@page import="java.util.Map"%>
<%@page import="com.shsh.safemanage.util.RequestUtil"%>
<%@page import="com.shsh.safemanage.action.ActionCreator"%>
<%@page import="com.shsh.safemanage.action.AdminAction"%>
<%@ page language="java" pageEncoding="UTF-8"%>
<%@page import="com.shsh.safemanage.model.User"%>
<%@page import="com.shsh.safemanage.util.Constants"%>
<%@page import="java.util.List"%>
<%@page import="java.util.ArrayList"%>

<div class="hider" id="hider">
	<span>&nbsp;</span>
</div>
<div class="position">
	<img src="../images/position2.jpg" style="padding: 7px 9px; float: left;" />当前位置：上海高桥分公司问题管理平台 &gt;&gt; 系统管理&gt;&gt; 已注册员工列表
</div>

<%
{
	int pageNum = RequestUtil.getParameter(request, Constants.REQUEST_PARAMETER_PAGE_NUM, 1);
	AdminAction adminAction = ActionCreator.createAdminAction();
	boolean isSuccess = adminAction.getRegisteredUsers(request);
	
	List<User> userList = (List<User>)request.getAttribute(Constants.DAO_RESULT);
	if(userList == null){
		userList = new ArrayList<User>();
	}
	
	int userCount = (Integer) request.getAttribute(Constants.DAO_RESULT_NUMBER);
%>
<div class="tt">已注册员工列表</div>
<div class="content">
	<table align="center" border="0" width="700" cellpadding="0"
		cellspacing="0">
		<tr>
			<td class="td1" height="35" colspan="8">
			<%=pageNum==1?"上一页":"<a href=\"javascript:\" onclick=\"goPrevious()\">上一页</a>" %>
				<%=pageNum %>
			<%=userList.size()<Constants.PAGE_SIZE?"下一页":"<a href=\"javascript:\" onclick=\"goNext()\">下一页</a>" %>
			共 <%=userCount %> 个结果
			</td>
		</tr>
		<tr>
			<td class="td1" height="35" style="width:5%;" align="center">
				序号
			</td>
			<td class="td1" height="35" style="width:5%;" align="center">
				工号
			</td>
			<td  class="td1" height="35" style="width:8%;" align="center">				
				姓名
			</td>
			<td  class="td1" height="35" style="width:8%;" align="center">				
				密码
			</td>
			<td  class="td1" height="35" style="width:20%;" align="left">				
				一级单位
			</td>
			<td  class="td1" height="35" style="width:25%;" align="left">				
				二级单位
			</td>	
			<td  class="td1" height="35" style="width:20%;" align="left">				
				职位
			</td>	
			<td  class="td1" height="35" align="left">				
				&nbsp;
			</td>	
		</tr>
		<% 
		long index = Constants.PAGE_SIZE * (pageNum -1) + 1;	
		for (User user : userList) { 
		%>
		<tr>
			<td class="td1"  align="center">
				<%=index++ %>
			</td>
			<td class="td1"  align="center">
				<%=Util.getDisplay(user.getJobNum(), "&nbsp;")%>
			</td>
			<td class="td1"  align="center" >
				<%=Util.getDisplay(user.getName(), "&nbsp;") %>
			</td>
			<td class="td1"   align="center">
				<%=(user.getPassword()==null || user.getPassword().equals(""))? "&nbsp;":user.getPassword() %>
			</td>
			<td class="td1"   align="left" style="word-break: break-all; word-wrap:break-word;">
				<%=user.getDepartment1Name()%>
			</td>
			<td class="td1"   align="left" style="word-break: break-all; word-wrap:break-word;" >
				<%=user.getDepartment2Name()%>
			</td>
			<td class="td1"  align="left" style="word-break: break-all; word-wrap:break-word;" >
				<%=user.getDepartment3Name()%>
			</td>
			<td class="td1"   align="left" style="word-break: break-all; word-wrap:break-word;" >
				<a href="javascript:deleteUser(<%=user.getId()%>, '<%=user.getName() %>')" onclick="">删除</a>
			</td>
		</tr>
		<%}%>
		<tr>
			<td class="td1" height="35" colspan="8">
			<%=pageNum==1?"上一页":"<a href=\"javascript:\" onclick=\"goPrevious()\">上一页</a>" %>
				<%=pageNum %>
			<%=userList.size()<Constants.PAGE_SIZE?"下一页":"<a href=\"javascript:\" onclick=\"goNext()\">下一页</a>" %>
			共 <%=userCount %> 个结果
			</td>
		</tr>
	</table>
</div>
<script type="text/javascript">
function goPrevious(){
	loadPageSection(
			'<%=request.getContextPath()%>/admin/employee_list.jsp', 
			'mainContentDiv', 
			{
				<%=Constants.REQUEST_PARAMETER_PAGE_NUM%>: <%=pageNum - 1%>
			}, 
			true
	);
}

function goNext(){
	loadPageSection(
			'<%=request.getContextPath()%>/admin/employee_list.jsp', 
			'mainContentDiv', 
			{
				<%=Constants.REQUEST_PARAMETER_PAGE_NUM%>: <%=pageNum + 1%>
			}, 
			true
	);
}

function deleteUser(userID, userName){
	$.dialog.confirm('请小心删除，删除后用户'+userName+'的相关问题将无法恢复，是否确认删除？', function(){
		$.ajax({
			type:'post',
			url:'delete_user_process.jsp',
			data:{			
				userID: userID
			},
			success:function(data,state,xmlhttp){
				var obj = null;
				try {
					obj = eval('(' + data + ')');
				} catch (e) {
				}
				if (typeof(obj.isSuccess) != 'undefined') {
					closeWaitingDialog('waitingDialog');
					if (obj.isSuccess == 'true') {					
						$.dialog('删除成功！', function() { loadPageSection('<%=request.getContextPath()%>/admin/employee_list.jsp', 'mainContentDiv', {}, true); });					
					} else {
						$.dialog.alert(obj.error);
					}
				}
			}
		});
	});
}
</script>
<%
}
%>

